package com.jianzhile.jobs.fragments;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.jianzhile.jobs.R;
import com.jianzhile.jobs.activities.add.OthersActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 添加兼职信息
 */
public class AddFragment extends Fragment implements  View.OnClickListener{

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    @Bind(R.id.content_add_actor_ll)
    public LinearLayout actorAdd;
    @Bind(R.id.content_add_volunter_ll)
    public LinearLayout volenterAdd;
    @Bind(R.id.content_add_seal_ll)
    public LinearLayout sealAdd;
    @Bind(R.id.content_add_teacher_ll)
    public LinearLayout teatherAdd;
    @Bind(R.id.content_add_hands_out_ll)
    public LinearLayout handsOutAdd;
    @Bind(R.id.content_add_design_ll)
    public LinearLayout designAdd;
    @Bind(R.id.content_add_internet_ll)
    public LinearLayout internetAdd;
    @Bind(R.id.content_add_sub_work_ll)
    public LinearLayout subWorkAdd;
    @Bind(R.id.content_add_other_ll)
    public LinearLayout othersAdd;

    private OnFragmentInteractionListener mListener;

    public AddFragment() {
    }



    public static AddFragment newInstance(String param1, String param2) {
        AddFragment fragment = new AddFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_add, container, false);
        ButterKnife.bind(this, view);
        return  view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initListener();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;

        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }


    }



    private void initListener(){
        actorAdd.setOnClickListener(this);
        volenterAdd.setOnClickListener(this);
        sealAdd.setOnClickListener(this);
        teatherAdd.setOnClickListener(this);
        handsOutAdd.setOnClickListener(this);
        designAdd.setOnClickListener(this);
        internetAdd.setOnClickListener(this);
        subWorkAdd.setOnClickListener(this);
        othersAdd.setOnClickListener(this);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public void onClick(View v) {


        Intent intent = new Intent(getActivity(), OthersActivity.class);

        switch (v.getId()){
            case R.id.content_add_actor_ll:
                startActivity(intent);
                break;
            case R.id.content_add_volunter_ll:
                startActivity(intent);
                break;
            case R.id.content_add_seal_ll:
                startActivity(intent);
                break;
            case R.id.content_add_teacher_ll:
                startActivity(intent);
                break;
            case R.id.content_add_hands_out_ll:
                startActivity(intent);
                break;
            case R.id.content_add_design_ll:
                startActivity(intent);
                break;
            case R.id.content_add_internet_ll:
                startActivity(intent);
                break;
            case R.id.content_add_sub_work_ll:
                startActivity(intent);
                break;
            case R.id.content_add_other_ll:

                startActivity(intent);
                break;
        }
    }


    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);

        void initToolBar(int tab);
    }
}
